Skip to content

Conversation

@stephenctw
Copy link
Contributor

  • Update the emulator constants to include MANUAL_REASON
  • Reorder the constants to make storage more compact
  • Add AdvanceStatus.sol
  • Add Checkpoint getter/setter

Comment on lines 25 to 35
function getCheckpointHash(AccessLogs.Context memory a)
internal
pure
returns (bytes32)
{
return a.readLeaf(
Memory.strideFromLeafAddress(
EmulatorConstants.checkpointAddress.toPhysicalAddress()
)
);
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this function is returning the hash of the checkpoint hash. Can you verify?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If so, the procedure should be something like:

  • call readLeaf, store result at L;
  • consume another bytes32, which will be the "alleged" checkpoint hash itself. Store result inV;
  • check that the keccak of V matches L;
  • return V.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are right, I totally missed that.

Comment on lines 103 to 113
function setCheckpointHash(
AccessLogs.Context memory a,
bytes32 checkPointHash
) internal pure {
a.writeLeaf(
Memory.strideFromLeafAddress(
EmulatorConstants.checkpointAddress.toPhysicalAddress()
),
checkPointHash
);
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Likewise, I think this is writing the hash of the checkpoint hash. Can you verify?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If so, this function should keccak the checkpointHash before writing it.


uint32 constant IFLAGS_Y_SHIFT = 1;
uint64 constant LOG2_CYCLES_TO_RESET = 10;
uint64 constant checkpointAddress = 0x7ffff000;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should use screaming snake case for constants, as the other constants!

}

library AdvanceStatus {
// START OF AUTO-GENERATED CODE
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this autogenerated?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not but I supposed it'll be sometimes in the future. Would you like it to be removed?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I think if it's not auto generated, we should remove it.

Comment on lines 44 to 46
uint64 tohost =
EmulatorCompat.readWord(a, EmulatorConstants.HTIF_TOHOST_ADDRESS);
uint16 reason = uint16((tohost >> 16) & ((1 << 16) - 1));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add comments about the endianness, and layout of the tohost register:

typedef struct cmt_io_yield {
    uint8_t dev;
    uint8_t cmd;
    uint16_t reason;
    uint32_t data;
} cmt_io_yield_t;

Comment on lines 25 to 30
enum Status {
NOT_YIELDED,
ACCEPTED,
REJECTED,
EXCEPTION
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should move this type inside library AdvanceStatus so that it becomes "scoped" to that library.

@GCdePaula
Copy link
Contributor

Just checked the new commits, looks great to me. I've added an additional style comment.

I'd love for @mpernambuco to take a look as well.

Note for reviewers, extracting the yield reason from tohost has some tricky endianness logic, but upon closer inspection it seems it's not really an issue.

@stephenctw stephenctw force-pushed the feature/add-checkpoint-primitives branch 2 times, most recently from d0f127f to 31de9b1 Compare August 20, 2025 04:56
)
);
assert(keccak256(abi.encodePacked(checkpointHash)) == hashOfCheckpointHash);
assert(
Copy link
Contributor

@GCdePaula GCdePaula Aug 20, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I missed this: I think this is a require and not an assert.

@stephenctw stephenctw force-pushed the feature/add-checkpoint-primitives branch from 31de9b1 to 2753737 Compare August 20, 2025 13:57
@stephenctw stephenctw force-pushed the feature/add-checkpoint-primitives branch from 2753737 to 96a22c9 Compare August 25, 2025 07:54
@stephenctw stephenctw force-pushed the feature/add-checkpoint-primitives branch from 289984a to e8050dd Compare September 22, 2025 12:34
@edubart edubart moved this from Todo to In Progress in Machine Unit Nov 6, 2025
@edubart edubart added the enhancement New feature or request label Nov 6, 2025
@edubart edubart moved this from In Progress to Waiting Review in Machine Unit Nov 27, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

Status: Waiting Review

Development

Successfully merging this pull request may close these issues.

4 participants